<template>
  <div class="recoveryIndex">
    <Header>
      <span> 找回密码 </span>
    </Header>
    <section>
      <div class="iphone">
        <input
          type="text"
          placeholder="请输入修改后的密码"
          pattern="[0-9]*"
          v-model="pwdLogin"
          autocomplete="off"
        />
      </div>
      <div class="log" @click="changePwd">确 认</div>
    </section>
  </div>
</template>

<script>
import Header from "@/components/Login/Header.vue";
import { Toast } from "mint-ui";
import http from "@/common/request";
export default {
  components: {
    Header,
  },
  data() {
    return {

      pwdLogin: "",
      rules: {
        pwdLogin: {
          rule: /^\w{6,12}$/,
          msg: "密码不能为空,并且是6-12位数字",
        },
      },
    };
  },
  methods: {
   async changePwd() {
      if (!this.validate("pwdLogin")) return;
      // 发送请求 确认修改
      let res = await http.$axios({
        url:'/api/recovery',
        method:'post',
        data:{
          phone:this.$route.query.phone,
          pwd:this.pwdLogin
        }
      })
      if(res.data.success){
        this.$router.push({
          name:'UserLogin'
        })
      }
      console.log(res);
    },

    validate(key) {
      let bool = true;
      if (!this.rules[key].rule.test(this[key])) {
        Toast(this.rules[key].msg);
        bool = false;
        return false;
      }
      return bool;
    },
  },
};
</script>

<style scoped>
.recoveryIndex {
  height: 100vh;
  width: 100vw;
  background-color: #eee;
}
.userLogin {
  height: 100vh;
  width: 100vw;
  background-color: #eee;
}
section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 40px;
}
.iphone,
.yzm {
  height: 40px;
  width: 80%;
  margin-bottom: 20px;
}
.iphone input {
  width: 100%;
  height: 100%;
  outline: none;
  padding-left: 10px;
}
.yzm {
  display: flex;
  height: 40px;
}
.yzm input {
  padding-left: 10px;
  width: 170px;
  height: 40px;
  outline: none;
}
.yzm .btn {
  box-sizing: border-box;
  height: 100%;
  flex: 1;
  font-size: 15px;
  border: 1px solid red;
  border-radius: 5px;
  text-align: center;
  line-height: 40px;
  background-color: red;
  color: antiquewhite;
  font-weight: 700;
}
.log {
  width: 80%;
  height: 40px;
  background-color: rgba(225, 0, 0, 1);
  border-radius: 10px;
  text-align: center;
  line-height: 40px;
  font-size: 18px;
  color: #eee;
}
</style>